<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="<?=site_url('admini')?>">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="<?=site_url('admini/sort')?>">分类管理</a><span class="crumb-step">&gt;</span><span>新增分类</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form action="<?=site_url('admini/sort/create')?>" method="post" id="myform" name="myform" enctype="multipart/form-data">
                    <table class="insert-tab" width="100%">
                        <tbody><tr>
                            <th width="120"><i class="require-red">*</i>上级分类：</th>
                            <td id="sort">
                                <select name="pid" id="catid" class="required top_0" onchange="getsort(0,this.value)">
                                	<option value="0">--顶级分类--</option>
                                    <?php foreach ($list as $k => $v):?>
                                    <option value="<?=$v['id']?>"><?=$v['name']?></option>
                                    <?php endforeach;?>
                                </select>
                            </td>
                        </tr>
                            <tr>
                                <th><i class="require-red">*</i>分类名称：</th>
                                <td>
                                    <input class="common-text required" id="title" name="name" size="50" value="" type="text">
                                </td>
                            </tr>
                            <tr>
                                <th>描述信息：</th>
                                <td><textarea name="depict" class="common-textarea" id="content" cols="20" style="width: 50%;" rows="5"></textarea></td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" type="submit">
                                    <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                                </td>
                            </tr>
                        </tbody></table>
                </form>
            </div>
        </div>
<script>

	//ajax 提交分类数据
	$('#myform').submit(function() {
        $(this).ajaxSubmit(function(data){
            if(data == 1){
            	$("input[name=name]").val("");
                layer.alert('操作成功！',{
                    icon:1,
                });
            }else{
                layer.alert(data,{
                    icon:2,
                });
            }
        })
        return false;
    })



	function getsort(top,pid){
		
		//删除
		var k = top*1+1;
		$("#sort select").each(function(){
			$(".top_"+k).remove();
			k ++;
		})
		if(pid == 0){
			return false;
		}
		
		//判断是否是上级分类
		var sv = $(".top_"+(top*1-1)).val();
		if(sv === pid){
			return false;
		}
		
		$.post("<?=site_url('admini/sort/getsort')?>",{sid:pid},function(data){
			if(data == ''){
				return false;
			}
			var l = '<select name="pid" id="catid" class="required top_'+(top*1+1)+'" onchange="getsort('+(top*1+1)+',this.value)">';
			l += '<option value="'+pid+'">--上级分类--</option>';
			$(data).each(function(){
				l += '<option value="'+this.id+'">'+this.name+'</option>';
			})
			l += '</select>';
			$(".top_"+top).after(l);
		},'json');
	}
	
</script>